package com.yc.config;


import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;


import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
import com.yc.entity.Morder;
import org.springframework.stereotype.Component;

@Component
public class AlipayConfig{

    private Config aliconfig() {
        Config config = new Config();
        //沙箱支付宝地址
        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
        //协议https
        config.protocol = "https";
        //应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
        config.appId = "9021000143691166 ";
        //支付宝公钥
        config.alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqO8OArED4Ivsxl8aDJYTnWugo/7pfL98kkUrcmOdwhw19juGJsxpB8iuM4u6VT4IbAUMphBOEuXmQ5OInwBEkizEeIjv8aQFX3Pj/Fl+tvjGver6llNETqMYiKgGYOLHKIzN9ALyH5p9NdgKBeoDaVgl8DKhwt0uMVmV3VBq6Bs0YkMqdnGSws0FcT7ee4v7+7RFWAlAkx/fu6mh+JAZ+PXIRKqtnAU0tQy8zoAfEG271YVDlszmVTYMizH1vG7uWfn0S2MgChacpReeEHqzKarymFcs5DzC/q+QkRnS0gz9/maSADE48anLA7bNp46/xX3RKZT5n0fWWHdj0XNubwIDAQAB";
        //签名方式
        config.signType = "RSA2";
        //商户私钥（应用私钥），您的PKCS8格式RSA2私钥
        config.merchantPrivateKey ="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC3rpmBHX+Yxw1kV6O8dvz0KuCDalCyIIV4o5XMMwsocLjo5ICjcC3gcWJo6GlpNzyVGjBov26/br3uOugJpxIPd8OvAqvTlnGqFCK0oUsFwxSd3xxqdFzbrGxmqxC2xpoUOz1yeUXbdDaXx9yzeTLigY96ZmBeTZtP14AvQrtwU9m7MBIjOjxClecZ/TAMjjDeXC0vTR4Zzf5F/AZhmTqYCKfIMX6YA9uyv2qZgtnv9X2hcDqPpHRPuBdfD+R7hoLDnTzUKh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lpY7XyxGMAFl7+ctAYaVp1tbPA7VKTGdIni+mrmOj79Wbm6CckEdAoGAcHJWt9xWM7YncPqgjSYnUB8DvycUDaMVHZFSN2IeHnKsOEtjuO5DeTaU+2T+qw3pJbdxigzCixfhQ5hM2uGwTtyvDKpNn3ZkUnatEfcgnU4zB9lr98wKtwboa+7LSypnPHkHvNXeaJgNPXqTHY/a6ZAec6v0/cX8vaiQT1OVODo=";
        return config;
    }

    public String goAlipay(Morder order) {
        try {
            // 1. 设置参数（全局只需设置一次）
            Factory.setOptions(aliconfig());
            // 2. 发起API调用（subject商品标题、outTradeNo订单编号、totalAmount总金额、returnUrl异步通知地址）
            AlipayTradePagePayResponse response = Factory.Payment.Page()
                    .pay("SpringBoot练手项目收款",
                            order.getOid().toString(),//订单,编号
                            order.getTotalprice().toString(),

                            //总金额
                            //支付成功之后的异步通知（跳出到自己系统的哪个位置）
                            "https://127.0.0.1/market-order/morder/payDone");
            return response.body;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }



}
